package com.hnhy.hnhyscms_ws.controller;

import com.hnhy.hnhyscms_ws.entity.Users;
import com.hnhy.hnhyscms_ws.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(value = "/users")
public class UsersController {
    @Autowired
    private IUsersService iUsersService;
    @RequestMapping(value = "/loginUsers",method = RequestMethod.POST)
    private Users loginUsers(@RequestParam String username,@RequestParam String password){
        return iUsersService.getByIdAndName(username,password);
    }
    @RequestMapping(value = "/WXloginUsers",method = RequestMethod.POST)
    private Users WXloginUsers(@RequestBody Users users){
        return iUsersService.getByIdAndName(users.getUsername(),users.getPassword());
    }
    @RequestMapping(value = "/getAllUsers",method= RequestMethod.GET)
    private List<Users> getAllUsers(){ return iUsersService.getAllUsers(); }
    @RequestMapping(value = "/change",method = RequestMethod.POST)
    private void change(@RequestParam String username,
                        @RequestParam String password,
                        @RequestParam String phone,
                        @RequestParam String remarks){
        Users users =new Users();
        users.setUsername(username);
        users.setPassword(password);
        users.setPhone(phone);
        users.setRemarks(remarks);
        iUsersService.change(users);
    }
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    private void delete(@RequestParam String username){
        iUsersService.delete(username);
    }
    @RequestMapping(value = "/addUser",method = RequestMethod.POST)
    private void addUser(@RequestParam String username,
                         @RequestParam String password,
                         @RequestParam Byte status,
                        @RequestParam String phone,
                        @RequestParam String remarks){
        Users users =new Users();
        users.setUsername(username);
        users.setPassword(password);
        users.setStatus(status);
        users.setPhone(phone);
        users.setRemarks(remarks);
        iUsersService.addUser(users);
    }
}
